﻿#region License

// Droid Manager - An Android Phone Tools Suite
// Copyright (C) 2011
// 
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#endregion

using System;
using System.Windows.Forms;
using DroidManager.Log;
using Managed.Adb;

namespace DroidManager.UI
{
    internal partial class DeviceInfo : Form
    {
        internal DeviceInfo()
        {
            InitializeComponent();
            _log = Logger.Instance;
        }

        private Device _device;
        private Logger _log;

        private Screenshot ss = new Screenshot();

        private void LoadInfo(Device device)
        {
            try
            {
                _device = device;
                serialLbl.Text = device.SerialNumber;
                nameLbl.Text = device.Name;
                emuLbl.Text = device.IsEmulator.ToString();
                stateLbl.Text = device.State.ToString();
                if (device.State == DeviceState.Online)
                {
                    versionLbl.Text = device.GetProperty(Device.PROP_BUILD_VERSION);
                    apiLbl.Text = device.GetProperty(Device.PROP_BUILD_API_LEVEL);
                }
                else
                {
                    versionLbl.Text = "Not Available";
                    apiLbl.Text = "Not Available";
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                _log.Error(e.ToString());
                return;
            }
        }

        internal void ShowDialog(Device device)
        {
            LoadInfo(device);
            base.ShowDialog();
        }

        private void closeBtn_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ss.ShowDialog(_device);
        }
    }
}